<template>
  <div v-if="data?.length <= 4" :style="dynamicBackgroundStyle" class="projectSelectBox">
    <div class="list" v-for="item in data" @mouseenter="mouseenter(item, index)" @click="confirmProject(item)">
      <div class="title">{{ item.projectName }}</div>
      <div class="informBox">
        <div class="info" style="margin-right: 35px;">
          <div class="img">
            <Image :preview="false" :src="projectSelect01"></Image>
          </div>
          <div class="textBox">
            <div class="titleInfo">飞行总架次</div>
            <div class="text">{{ item.totalFlightSorties }} 次</div>
          </div>
        </div>

        <div class="info" style="margin-left: 35px;">
          <div class="img">
            <Image :preview="false" :src="projectSelect02"></Image>
          </div>
          <div class="textBox">
            <div class="titleInfo">飞行总时长</div>
            <div class="text">{{ item.totalFlightTime }} h</div>
          </div>
        </div>
      </div>
      <div class="dataChartBox">
        <div class="left">
          <div class="infoBox" style="margin-bottom: 29px;">
            <div class="img">
              <Image :preview="false" :src="projectSelect06"></Image>
            </div>
            <div class="number">
              {{ item.videoNum }}
            </div>
          </div>

          <div class="infoBox">
            <div class="img">
              <Image :preview="false" :src="projectSelect07"></Image>
            </div>
            <div class="number">
              {{ item.imgNum }}
            </div>
          </div>
        </div>
        <div class="right">
          <Bar width="206px" height="200px" ref="BarRef" :option="chartConfigure" :chartData="item.chartData"></Bar>
        </div>
      </div>
      <div class="cameraInformBox">
        <div class="cameraInform">
          <div class="img">
            <Image :preview="false" :src="projectSelect05"></Image>
          </div>
          <div class="cameraInformText">全景图</div>
          <div class="cameraInformNumber">{{ item.panoramaNum }}</div>
        </div>

        <div class="cameraInform">
          <div class="img">
            <Image :preview="false" :src="projectSelect04"></Image>
          </div>
          <div class="cameraInformText">倾斜摄影</div>
          <div class="cameraInformNumber">{{ item.obliquePhotographNum }}</div>
        </div>

        <div class="cameraInform">
          <div class="img">
            <Image :preview="false" :src="projectSelect03"></Image>
          </div>
          <div class="cameraInformText">正射影像</div>
          <div class="cameraInformNumber">{{ item.positiveProjectiveImageNum }}</div>
        </div>
      </div>
    </div>
  </div>

  <div v-else :style="dynamicBackgroundStyle" class="projectSelectBoxTwo">
    <div class="listTwo" v-for="(item, index) in data" @mouseenter="mouseenter(item, index)"
      @click="confirmProject(item)">
      <div class="title">{{ item.projectName }}</div>
      <div class="informBox">
        <div class="info" style="margin-right: 35px;">
          <div class="img">
            <Image :preview="false" :src="projectSelect01"></Image>
          </div>
          <div class="textBox">
            <div class="titleInfo">飞行总架次</div>
            <div class="text">{{ item.totalFlightSorties }} 次</div>
          </div>
        </div>

        <div class="info" style="margin-left: 35px;">
          <div class="img">
            <Image :preview="false" :src="projectSelect02"></Image>
          </div>
          <div class="textBox">
            <div class="titleInfo">飞行总时长</div>
            <div class="text">{{ item.totalFlightTime }} h</div>
          </div>
        </div>
      </div>
      <div class="dataChartBox">
        <div class="left">
          <div class="infoBox">
            <div class="img">
              <Image :preview="false" :src="projectSelect06"></Image>
            </div>
            <div class="number">
              {{ item.videoNum }}
            </div>
          </div>

          <div class="infoBox">
            <div class="img">
              <Image :preview="false" :src="projectSelect07"></Image>
            </div>
            <div class="number">
              {{ item.imgNum }}
            </div>
          </div>
        </div>
        <div class="right">
          <Bar width="132px" height="104px" ref="BarRef" :option="chartConfigure" :chartData="item.chartData"></Bar>
        </div>
      </div>
      <div class="cameraInformBox">
        <div class="BoxTwo">
          <div class="cameraInform">
            <div class="img">
              <Image :preview="false" :src="projectSelect05"></Image>
            </div>
            <div class="cameraInformText">全景图</div>
            <div class="cameraInformNumber">{{ item.panoramaNum }}</div>
          </div>

          <div class="cameraInform">
            <div class="img">
              <Image :preview="false" :src="projectSelect04"></Image>
            </div>
            <div class="cameraInformText">倾斜摄影</div>
            <div class="cameraInformNumber">{{ item.obliquePhotographNum }}</div>
          </div>
        </div>


        <div class="cameraInform">
          <div class="img">
            <Image :preview="false" :src="projectSelect03"></Image>
          </div>
          <div class="cameraInformText">正射影像</div>
          <div class="cameraInformNumber">{{ item.positiveProjectiveImageNum }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script  setup>
import { selectProject, saveSysUserSet } from './data.api'
import { VideoCameraFilled } from '@ant-design/icons-vue';
import Bar from '/@/components/chart/Bar.vue';
import { ref, onMounted, computed } from 'vue';
import { useRouter, useRoute } from "vue-router";
import { Image } from 'ant-design-vue';
import projectSelect01 from '@/assets/icons/projectSelect/projectSelect01.svg';
import projectSelect02 from '@/assets/icons/projectSelect/projectSelect02.svg';
import projectSelect03 from '@/assets/icons/projectSelect/projectSelect03.svg';
import projectSelect04 from '@/assets/icons/projectSelect/projectSelect04.svg';
import projectSelect05 from '@/assets/icons/projectSelect/projectSelect05.svg';
import projectSelect06 from '@/assets/icons/projectSelect/projectSelect06.svg';
import projectSelect07 from '@/assets/icons/projectSelect/projectSelect07.svg';
import projectSelectBG from '@/assets/icons/projectSelect/projectSelectBG.jpg';
const router = useRoute()
const routerR = useRouter();
const BarRef = ref()
let data = ref()
function getDate() {

}
let chartData = ref([
  {
    "name": "视频",
    "value": 50
  },
  {
    "name": "图片",
    "value": {
      value: 30,
      itemStyle: {
        borderColor: 'rgba(255, 231, 69, 0.6)', // 设置边框颜色
        borderWidth: 1, // 设置边框宽度
        borderRadius: [4, 4, 0, 0], // 上面两个角设置圆角半径
        color: {
          type: 'linear', // 指定渐变类型
          x: 0, // 渐变起点 x 坐标
          y: 0, // 渐变起点 y 坐标
          x2: 0, // 渐变终点 x 坐标
          y2: 1, // 渐变终点 y 坐标
          colorStops: [
            {
              offset: 0, color: '#beba54' // 渐变起点颜色
            },
            {
              offset: 1, color: '#7a8b64' // 渐变终点颜色
            }
          ],
        },
      }
    }
  }
])

const chartConfigure = {
  yAxis: {
    show: false, // 将左边的Y轴隐藏
  },
  series: [
    {
      // name: '示例数据',
      type: 'bar',
      label: {
        show: true, // 启用标签显示
        position: 'top', // 位置可以是 'top'、'insideTop'、'inside' 等
      },
      itemStyle: {
        borderColor: 'rgba(80,252,255,0.6)', // 设置边框颜色
        borderWidth: 1, // 设置边框宽度
        borderRadius: [4, 4, 0, 0], // 上面两个角设置圆角半径
        color: {
          type: 'linear', // 指定渐变类型
          x: 0, // 渐变起点 x 坐标
          y: 0, // 渐变起点 y 坐标
          x2: 0, // 渐变终点 x 坐标
          y2: 1, // 渐变终点 y 坐标
          colorStops: [
            {
              offset: 0, color: '#4ac4cd' // 渐变起点颜色
            },
            {
              offset: 1, color: '#4a959b' // 渐变终点颜色
            }
          ],
        },
      },
    },
  ]
}

function listMouseover(event) {
  console.log(event)
}

async function confirmProject(item) {
  const saveConfigure = await saveSysUserSet({
    userId: localStorage.getItem('userId'),
    type: 0,
    content: item.id
  })
  const myArray = [item.longitude, item.latitude]
  localStorage.setItem('latitudeLongitude', JSON.stringify(myArray))
  localStorage.setItem('Project_Id', item.id);
  routerR.push({ path: '/projectManage/projectDetail', query: { id: item.id } })
}
const status = ref('1')
// 计算属性来动态生成背景图片样式
const dynamicBackgroundStyle = computed(() => {
  let backgroundUrl;
  if (status.value === "1") {
    backgroundUrl = projectSelectBG;
  } else {
    backgroundUrl = '';
  }

  return {
    background: `url(${backgroundUrl}) no-repeat center`,
  };
});

function mouseenter(item, index) {
  let a = item.chartData[0].value
  let b = item.chartData[1].value.value
  console.log(item, index)
  data.value[index].chartData[0].value = 0
  data.value[index].chartData[1].value.value = 0
  data.value[index].chartData[0].value = a
  data.value[index].chartData[1].value.value = b
}

onMounted(async () => {
  data.value = await selectProject({ userId: router.query.userId })
  data.value = data.value.map((item) => {
    return {
      ...item,
      chartData: [
        {
          "name": "视频",
          "value": item.videoNum,
          // "value": 50,
        },
        {
          "name": "图片",
          "value": {
            // value: 30,
            value: item.imgNum,
            itemStyle: {
              borderColor: 'rgba(255, 231, 69, 0.6)', // 设置边框颜色
              borderWidth: 1, // 设置边框宽度
              borderRadius: [4, 4, 0, 0], // 上面两个角设置圆角半径
              color: {
                type: 'linear', // 指定渐变类型
                x: 0, // 渐变起点 x 坐标
                y: 0, // 渐变起点 y 坐标
                x2: 0, // 渐变终点 x 坐标
                y2: 1, // 渐变终点 y 坐标
                colorStops: [
                  {
                    offset: 0, color: '#beba54' // 渐变起点颜色
                  },
                  {
                    offset: 1, color: '#7a8b64' // 渐变终点颜色
                  }
                ],
              },
            }
          }
        }
      ]
    }
  })
  console.log(data.value)

  // for (var i = 0; i < 20; i++) {
  //   chartData.value[0].value++
  // }


})


</script>
<style lang="less" scoped>
.projectSelectBox {
  box-sizing: border-box;
  height: 100vh;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  background-color: beige;
  flex-wrap: wrap;
  overflow: auto;
  // background: url("../../../assets/icons/projectSelect/projectSelectBG.jpg") no-repeat center;
  padding: 40px;

  .list {
    background: rgba(147, 181, 194, 0.1);
    box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    backdrop-filter: blur(10px);
    display: inline-block;
    // margin-right: 82px;
    margin-bottom: 40px;
    // width: calc(33.33% - 100px);

    .title {
      font-size: 24px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #FFFFFF;
      text-align: center;
      margin-top: 39px;
    }

    .informBox {
      display: flex;
      align-items: center;
      margin-top: 42px;
      margin-left: 32px;
      margin-right: 47px;
      margin-bottom: 42px;

      .info {
        display: flex;
        align-items: center;

        .img {
          width: 48px;
          height: 48px;
          // background-color: aqua;
          margin-right: 19px;
        }

        .textBox {
          .titleInfo {
            font-size: 16px;
            font-weight: 400;
            color: #FFFFFF;
          }

          .text {
            font-size: 24px;
            font-weight: 500;
            color: #FFFFFF;
          }
        }
      }

    }

    .dataChartBox {
      background: rgba(147, 181, 194, 0.1);
      border-radius: 4px;
      margin-left: 16px;
      margin-right: 16px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 32px;

      .left {
        .infoBox {
          display: flex;

          .img {
            margin-right: 23px;

            .icon {
              font-size: 34px;
              color: #3d9dc4;

            }
          }

          .number {
            font-size: 20px;
            font-weight: 500;
            color: #FFFFFF;
          }
        }
      }

      .right {}
    }

    .cameraInformBox {
      padding-left: 31px;
      margin-top: 47px;
      margin-bottom: 119px;
      // margin-bottom: var();

      .cameraInform {
        display: flex;
        align-items: center;
        margin-bottom: 18px;

        .img {
          width: 30px;
          height: 30px;
          // background-color: aqua;
          margin-right: 17px;
        }

        .cameraInformText {
          font-size: 16px;
          font-weight: 400;
          color: #FFFFFF;
          width: 88px;
          margin-right: 20px;
        }

        .cameraInformNumber {
          font-size: 16px;
          font-weight: 400;
          color: #FFFFFF;
        }
      }
    }
  }

  .list:hover {
    background-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.15);
    border: 1px solid #8eb8c9;
    backdrop-filter: blur(10px);
    // transition: 0.5s ease;
  }
}

.projectSelectBoxTwo {
  box-sizing: border-box;
  height: 100vh;
  background-color: beige;
  flex-wrap: wrap;
  overflow: auto;
  // background: url("@/assets/icons/projectSelect/projectSelectBG.jpg") no-repeat center;
  padding: 40px;

  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-gap: 60px;

  .listTwo {
    background: rgba(147, 181, 194, 0.1);
    box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    backdrop-filter: blur(10px);
    display: inline-block;
    // margin-right: 82px;
    // margin-bottom: 25px;
    // width: calc(33.33% - 100px);

    .title {
      font-size: 24px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #FFFFFF;
      text-align: center;
      margin-top: 39px;
    }

    .informBox {
      display: flex;
      align-items: center;
      margin-top: 40px;
      margin-left: 23px;
      margin-right: 23px;
      margin-bottom: 34px;

      .info {
        display: flex;
        align-items: center;

        .img {
          width: 48px;
          height: 48px;
          // background-color: aqua;
          margin-right: 19px;
        }

        .textBox {
          .titleInfo {
            font-size: 16px;
            font-weight: 400;
            color: #FFFFFF;
          }

          .text {
            font-size: 24px;
            font-weight: 500;
            color: #FFFFFF;
          }
        }
      }

    }

    .dataChartBox {
      background: rgba(147, 181, 194, 0.1);
      border-radius: 4px;
      margin-left: 16px;
      margin-right: 16px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 32px;

      .left {
        display: flex;
        flex-direction: column;
        align-items: center;

        .infoBox {
          display: flex;
          // margin-bottom: 15px;
          align-items: center;

          .img {
            margin-right: 23px;

            .icon {
              font-size: 34px;
              color: #3d9dc4;

            }
          }

          .number {
            font-size: 20px;
            font-weight: 500;
            color: #FFFFFF;
          }
        }
      }

      .right {}
    }

    .cameraInformBox {
      padding-left: 21px;
      padding-right: 21px;
      margin-top: 21px;
      // margin-bottom: 119px;
      // margin-bottom: var();

      .BoxTwo {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }

      .cameraInform {
        display: flex;
        align-items: center;
        margin-bottom: 18px;

        .img {
          width: 30px;
          height: 30px;
          // background-color: aqua;
          margin-right: 17px;
        }

        .cameraInformText {
          font-size: 16px;
          font-weight: 400;
          color: #FFFFFF;
          width: 88px;
          margin-right: 20px;
        }

        .cameraInformNumber {
          font-size: 16px;
          font-weight: 400;
          color: #FFFFFF;
        }
      }
    }
  }

  .listTwo:hover {
    background-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.15);
    border: 1px solid #8eb8c9;
    backdrop-filter: blur(10px);
    // transition: 0.5s ease;
  }
}
</style>
